// ConfirmEventSink.cpp : implementation file
//

#include "stdafx.h"
#include "SpeedOrder.h"
#include "ConfirmEventSink.h"
#include "wp2_i_5.c"

// CConfirmEventSink
#include "OrderManager.h"


CConfirmEventSink::CConfirmEventSink()
{
	m_refCount = 1;
	m_lpCp = NULL;
	m_pOrderMgr = NULL;
}

CConfirmEventSink::~CConfirmEventSink()
{

}

// IUnknown methods.
HRESULT __stdcall CConfirmEventSink::QueryInterface(
	REFIID riid, void **ppvObject) {
	if (
		IsEqualGUID(riid, IID_IDispatch) ||
		IsEqualGUID(riid, IID_IUnknown) ||
		IsEqualGUID(riid, DIID_IGxConfirmEvents)
		) {
		this->AddRef();
		*ppvObject = this;
		return S_OK;
	}
	*ppvObject = NULL;
	return E_NOINTERFACE;
}

ULONG _stdcall CConfirmEventSink::AddRef(void) {
	return ++m_refCount;
}

ULONG _stdcall CConfirmEventSink::Release(void) {
	if (--m_refCount <= 0) {
		//Delete this;
		return 0;
	}
	return m_refCount;
}

// IDispatch methods.
HRESULT _stdcall CConfirmEventSink::GetTypeInfoCount(UINT *pctinfo) {
	if (pctinfo) *pctinfo = 0;
	return E_NOTIMPL;
}

HRESULT _stdcall CConfirmEventSink::GetTypeInfo(
	UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) {
	return E_NOTIMPL;
}

HRESULT _stdcall CConfirmEventSink::GetIDsOfNames(
	REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid,
	DISPID *rgDispId) {
	return E_NOTIMPL;
}

HRESULT _stdcall CConfirmEventSink::Invoke(
	DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
	DISPPARAMS *pDispParams, VARIANT *pVarResult,
	EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
	int count = m_lpConfirms.GetCount();
	m_lpConfirm = m_lpConfirms.GetItem(COleVariant((long) count));
	if (dispIdMember == 1)
	{
		m_pOrderMgr->OnNewConfirm(m_lpConfirm);
	}
	return S_OK;
}